<template>
  <div>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <van-card
        v-for="item in productList"
        :key="item.id"
        num="2"
        :price="item.price"
        :title="item.name"
        :desc="item.subTitle"
        :thumb="item.pic"
        @click="handleProject(item)"
      >
          <template #tags>
              <van-tag plain type="danger" v-if="item.promotionType >0">活动</van-tag>
            </template>
        <template #footer>
          <van-button size="mini" @click.stop="handleVerify(item)">审核记录</van-button>
          <van-button size="mini" @click.stop="handleVerify(item)">审核</van-button>
        </template>
      </van-card>
    </van-list>

    <van-dialog v-model="verifyshow" title="审核意见" @confirm="onVerify" show-cancel-button>
      <van-field
        v-model="verparam.detail"
        rows="2"
        autosize
        label="审核意见"
        type="textarea"
        maxlength="120"
        placeholder="请输入留言"
        show-word-limit
      />
      <van-field name="radio" label="审核结果">
        <template #input>
          <van-radio-group v-model="verparam.state" direction="horizontal">
            <van-radio name="1">通过</van-radio>
            <van-radio name="3">拒绝</van-radio>
          </van-radio-group>
        </template>
      </van-field>
    </van-dialog>
  </div>
</template>

<script>
import { listProduct, verifyProduct } from "@/api/product";
export default {
  data() {
    return {
      finished: false,
      loading: false,
      error: false,
      verifyshow: false,

      productparam: {
        publishStatus: 2,
        pageSize: 10,
        pageNum: 1
      },
      verparam: {
        detail: "",
        state: "1",
        productId: 0
      },
      productList: []
    };
  },
  methods: {
    // 获取分类下商品
    onLoad() {
      listProduct(this.productparam).then(response => {
        this.productList = this.productList.concat(response.data);
        if (response.data.length == 0) {
          this.finished = true;
        }
        this.loading = false;
        this.productparam.pageNum = this.productparam.pageNum + 1;
        this.$forceUpdate();
      });
    },
    handleVerify(item) {
      this.verparam.detail = "";
      this.verparam.productId = item.id;
      this.verparam.state = "1";
      this.verifyshow = true;
    },
    onVerify() {
      verifyProduct(this.verparam).then(response => {
        this.productList = [];
        this.productparam.pageNum = 1;
        this.finished = false;
        this.loading = true;
        this.onLoad();
      });
    }
  }
};
</script>
<style scoped>
</style>